package br.edu.unip.locacao;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Datas {
	public String DataString(){
		GregorianCalendar gc = new GregorianCalendar();  
		gc.setTime(new Date());  
		SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy");
		String d =  dataFormatada.format(gc.getTime()) ;
		return d;
	}
	public Date StringData(String txt){
		SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy");
		Date data = null;
		  try {  
		      data = dataFormatada.parse(txt);  
		  } catch (java.text.ParseException e) {  
		      e.printStackTrace();  
		  }
		return data;
	}
	public long CalculoData(Date data, Date data2){
		Calendar data_retirada = new GregorianCalendar();
		Calendar data_entrega = new GregorianCalendar();
		data_retirada.setTime(data);
		data_entrega.setTime(data2);
		long time = data_entrega.getTime().getTime() - data_retirada.getTime().getTime(); 
		long days = Math.round( (double)time / (24. * 60.*60.*1000.) ); 
		return days;
	}
}